package com.powernode.controller;

import com.powernode.framework.Result;
import com.powernode.framework.ResultBean;
import com.powernode.framework.ResultUtil;
import com.powernode.pojo.TowerAdmin;
import com.powernode.service.TowerAdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: ycc
 * @Date: 2023/2/14 12:24
 */
@RestController
@RequestMapping("/api/towerAdmin")
public class TowerAdminController {
    @Resource
    TowerAdminService towerAdminService;


    @GetMapping("/list")
    public ResultBean<List<TowerAdmin>> getPageResult(HttpServletRequest request) {
        HttpSession session = request.getSession();
        // 从session中获取用户信息
        TowerAdmin loginUser = (TowerAdmin) session.getAttribute("towerAdmin");

        Map<String, Object> param = new HashMap<>(16);
        // 获取当前页结果集
        List<TowerAdmin> entities = new ArrayList<>();
        entities.add(towerAdminService.selectByTowerSite(loginUser.getTowerSite()));
        return new ResultBean<>(0, "查询成功", 10,entities);
    }

    @PostMapping("/save")
    public Result<String> insert(@RequestBody TowerAdmin entity){
        System.out.println("++++++++++++++++++++++++++++\n------------------------------------\n++++++++++++++++++++++++++++++");
        System.out.println(entity.toString());
        System.out.println(entity.getId());
        if (entity.getId()==null)
            towerAdminService.insert(entity);
        else
            towerAdminService.update(entity);
        return ResultUtil.ok();
    }

    @PostMapping("/remove")
    Result<String> delete(@RequestBody Integer[] ids){
        towerAdminService.delete(ids);
        return ResultUtil.ok();
    }
}
